home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 19 / Mac Magazin and MacEasy Magazine CD - Issue 19.iso / Wissenschaft & Technik / Open Prolog / Documents / Exception Handling < prev    next >
Text File  |  1993-09-25  |  3KB  |  72 lines

  1. • Exception handling using catch-and-throw (Open Prolog 1.0d37 and later).
  2.  
  3. <Information to be added. In the meantime, consult the ISO Prolog draft>
  4.  
  5. • Exception Handling in built-in predicates in Open Prolog
  6.  
  7. Whenever an error is discovered in a built-in, an error term is thrown. If no catch/3 predicate intervenes, the error term will be caught by the default catcher which will output a suitable error message and abort the program.
  8.  
  9. The form of the term that's thrown is: error(Kind,ListOfInformation).
  10. The Kind is one of the ISO Prolog Draft errors, plus two more. Here is the list of all of them:
  11.  
  12. unclassified_error    %this is not part of ISO
  13. user_interrupt %this is not part of ISO
  14.  
  15. system_error %a system_error can't be caught by a catch/3 predicate.
  16. calculation_error
  17. database_error
  18. evaluation_error
  19. implementation_error
  20. instantiation_error
  21. io_control_error
  22. io_end_of_file_error
  23. io_formatting_error
  24. operator_error
  25. overflow_error
  26. domain_error %was range_error
  27. syntax_error
  28. type_error
  29. undefined_predicate_error
  30. undefined_value_error
  31. underflow_error
  32. zero_divide_error
  33.  
  34. At the moment, the majority of built-ins report an unclassified_error. As time goes by, they will be correctly classified.
  35.  
  36. To see some errors being thrown and caught, try the following predicates:
  37.  
  38. tab(_).
  39. tab(a).
  40. tab(-1).
  41. listing(_).
  42. see('non existent file').
  43. tell('non existent volume:file').
  44. X is a.
  45.  
  46. The ListOfInformation may contain auxiliary information that might be helpful to an error handler, or it could be empty. Auxiliary information will be of the form <category>(Information). This scheme is flexible, in that the list can contain anything remotely useful, and the error handler can access anything it understands while ignoring the rest. As Open Prolog evolves, the auxiliary information may increase. The following terms are used at present:
  47.  
  48. argument_index(OffendingArgumentNumber)    %starting at 1
  49.  
  50. argument(OffendingArgument). Variables in arguments may be instantiated as a result of the partial execution of the built-in.
  51.  
  52.  
  53. goal(Call). This is the goal in which the exception occured. Terms that were variables at the start of the call may be instantiated as a result of the partial execution of the built-in.
  54.  
  55. If the Call has very complex arguments (e.g. as a result of an occur check violation), the error handler may itself hang up. If you abort under these circumstances, you lose the error information - sorry.
  56.  
  57. error_code(ErrorCode). This will be an Open Prolog error code. The built-in 'get$prolog$error$message'(Code,Message) can be used to retrieve the error message.
  58.  
  59. Example:
  60. 'get$prolog$error$message'(-32767,Message).
  61.  
  62. error_message(ErrorMessageAtom).
  63.  
  64. host_error_code(MacErrorCodeNumber). This will be a standard Macintosh error code. The built-in 'get$host$error$message'(Code,Message) can be used to retrieve the error message.
  65.  
  66. Example:
  67. 'get$host$error$message'(-39,Message).
  68.  
  69. host_error_message(MessageAtom). This will be a string of text from the Macintosh.
  70.  
  71. If you are building an error exception catcher, please do not assume that the order of appearance of auxiliary information in the list will remain stable during program execution, or even that the same amount of information will result each time the same error occurs. Furthermore, the amount and order of information will change as Open Prolog evolves, although the standard <category>s will remain the same, as far as possible.
  72.